/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tfredes.utils;

import java.util.StringTokenizer;
import tfredes.roteador.pacote.Pacote;

/**
 *
 * @author Rodrigo
 */
public class Utils {
    
    public static Pacote convertStringToPacote(String stPacote) {
        Pacote pacote = new Pacote();
        StringTokenizer st = new StringTokenizer(stPacote, ":");
        pacote.setIpOrigem(st.nextToken());
        pacote.setPortaOrigem(Integer.valueOf(st.nextToken()));
        pacote.setIpDestino(st.nextToken());
        pacote.setPortaDestino(Integer.valueOf(st.nextToken()));
        pacote.setControleErro(Integer.valueOf(st.nextToken()));
        pacote.setPacote(st.nextToken());
        
        return pacote;
    }
    
    public static String convertPacoteToString(Pacote pacote) {
        String stPacote;
        stPacote = pacote.getIpOrigem()+":";
        stPacote = stPacote + pacote.getPortaOrigem()+":";
        stPacote = stPacote +pacote.getIpDestino()+":";
        stPacote = stPacote +pacote.getPortaDestino()+":";
        stPacote = stPacote +pacote.getControleErro()+":";
        stPacote = stPacote +pacote.getPacote()+"";       
        
        return stPacote;
    }
    
}
